package lu.med.praxiswahl.wahlumed.client.kalender;

import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.table.TableColumn;

import lu.med.praxiswahl.wahlumed.client.utilities.ColumnWidthControler;
import lu.med.praxiswahl.wahlumed.client.wclient.Main;


/**
 * 
 * @author Lars Holger Roth
 */
public class WochenplanTable extends JTable
{
    /**
     * 
     */
    private static final long serialVersionUID = -5978953679620254239L;

    public WochenplanTable(WochenplanTableModel model)
    {
	super(model);
	this.setRowHeight(30);
	this.setDefaultRenderer(Object.class, new WochenplanRenderer(model));

	ColumnWidthControler c = new ColumnWidthControler(
		Main.COLUMNWIDTH_CONFIGURATION_FILE, "wochenPlantbl", this);

	TableColumn column = null;
	for (int i = 0; i < 8; i++)
	{
	    column = this.getColumnModel().getColumn(i);
	    switch (i)
	    {
	    case 0:
		column.setPreferredWidth(c.getColumnWidth(0));
		break;
	    case 1:
		column.setPreferredWidth(c.getColumnWidth(1));
		break;
	    case 2:
		column.setPreferredWidth(c.getColumnWidth(2));
		break;
	    case 3:
		column.setPreferredWidth(c.getColumnWidth(3));
		break;
	    case 4:
		column.setPreferredWidth(c.getColumnWidth(4));
		break;
	    case 5:
		column.setPreferredWidth(c.getColumnWidth(5));
		break;
	    case 6:
		column.setPreferredWidth(c.getColumnWidth(6));
		break;
	    case 7:
		column.setPreferredWidth(c.getColumnWidth(7));
		break;
	    }
	}
    }

    @Override
    public void tableChanged(TableModelEvent e)
    {
	super.tableChanged(e);
	ColumnWidthControler c = new ColumnWidthControler(
		Main.COLUMNWIDTH_CONFIGURATION_FILE, "wochenPlantbl", this);

	TableColumn column = null;
	for (int i = 0; i < 8; i++)
	{
	    column = this.getColumnModel().getColumn(i);
	    switch (i)
	    {
	    case 0:
		column.setPreferredWidth(c.getColumnWidth(0));
		break;
	    case 1:
		column.setPreferredWidth(c.getColumnWidth(1));
		break;
	    case 2:
		column.setPreferredWidth(c.getColumnWidth(2));
		break;
	    case 3:
		column.setPreferredWidth(c.getColumnWidth(3));
		break;
	    case 4:
		column.setPreferredWidth(c.getColumnWidth(4));
		break;
	    case 5:
		column.setPreferredWidth(c.getColumnWidth(5));
		break;
	    case 6:
		column.setPreferredWidth(c.getColumnWidth(6));
		break;
	    case 7:
		column.setPreferredWidth(c.getColumnWidth(7));
		break;
	    }
	}
	this.repaint();
    }

}
